import { createRouter, createWebHistory } from 'vue-router'
import store from '../store'
import Home from '../views/Home.vue'

// import Router from 'vue-router'
// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

import Login from '../views/Login.vue';
import Clear from '../views/Clear.vue';
import Index from '../views/mainentity/Index.vue';
import Heart1 from '../components/heart/heart1.vue';
import Heart2 from '../components/heart/heart2.vue';
import Diabetes1 from '../components/diabetes/diabetes1.vue'
import Diabetes2 from '../components/diabetes/diabetes2.vue'
import Grop1 from '../components/grop/grop1.vue'
import Grop2 from '../components/grop/grop2.vue'
import Grop3 from '../components/grop/grop3.vue'
import Echarts_test from '../components/echarts_test/echarts_test.vue';

const routes = [
  { path: '/login', name: '登录', component: Login, meta: { r: true } },
  // { path: '/clear', name: '清理', component: Clear},
  {
    path: "/",
    redirect: '/home'
  },
  // {
  //   path:"/*",
  //   redirect: '/home'
  // },
  // {
  //   path:"/*/",
  //   redirect: '/home'
  // },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    // show:true,
    // redirect:'/home',
    children: [
      { path: '/home', name: '首页', component: Index },
      { path: '/heart/heart1', name: '心血管疾病 1', component: Heart1 },
      { path: '/heart/heart2', name: '心血管疾病 2', component: Heart2 },
      { path: '/diabetes/diabetes1', name: '糖尿病 1', component: Diabetes1 },
      { path: '/diabetes/diabetes2', name: '糖尿病 2', component: Diabetes2 },
      { path: '/grop/grop1', name: '个人信息', component: Grop1 },
      { path: '/grop/grop2', name: '整体信息', component: Grop2 },
      { path: '/grop/grop3', name: '物联设备', component: Grop3 },
    ]
  },
  { path: '/*', redirect: '/home' }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  if (!to.meta.r) {
    if (store.getters.getInfo) {
      next();
    } else {
      next({ path: '/login' })
    }
  } else {
    next();
  }
  if (to.name) {
    document.title = to.name + '-' + '后台管理系统'
  }
})


export default router
